package com.xinqi.modules.user.users.third.controller.app;

import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.common.log.asynclog.annotation.AsyncLog;
import com.xinqi.common.log.asynclog.enums.AsyncOperaType;
import com.xinqi.common.log.asynclog.enums.AsyncType;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.user.users.third.service.UserThirdBindService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * APP -- 第三方用户绑定
 *
 * @version V1.0
 * @Title:
 * @ClassName: com.xinqi.modules.user.third.controller.app.UserThirdBindAppController.java
 * @Description:
 * @Copyright 星齐科技（云南）有限公司 - Powered By 技术部
 * @author: yyzhen
 * @date: 2023/7/17 17:21
 */
@RestController
@RequestMapping("/app/user-third-bind")
@RequiredArgsConstructor
public class UserThirdBindAppController {
    private final UserThirdBindService userThirdBindService;

    /**
     * 绑定QQ
     *
     * @Title:
     * @MethodName: bindQQ
     * [code]
     * @Return com.xinqi.common.base.response.R
     * @Exception
     * @Description:
     * @author: yyzhen
     * @date: 2023/3/8 15:40
     */
    @AsyncLog(title = "绑定QQ", asyncType = AsyncType.USER_INFO, operatorType = AsyncOperaType.USER_THIRD_BIND)
    @GetMapping("/bindQQ/{code}")
    public R<Void> bindQQ(@PathVariable String code) {
        if (userThirdBindService.bindQQ(LoginHelper.getUserId(), code)) {
            return R.ok(MessageUtils.message("sys.third.bind.QQ.success"));
        } else {
            return R.fail(MessageUtils.message("sys.third.bind.QQ.fail"));
        }
    }

    /**
     * 解绑QQ
     *
     * @Title:
     * @MethodName: unbindQQ
     * []
     * @Return com.xinqi.common.base.response.R
     * @Exception
     * @Description:
     * @author: yyzhen
     * @date: 2023/3/8 11:44
     */
    @AsyncLog(title = "解绑QQ", asyncType = AsyncType.USER_INFO, operatorType = AsyncOperaType.USER_THIRD_BIND)
    @PostMapping("unbindQQ")
    public R<Void> unbindQQ() {
        if (userThirdBindService.unbindQQ(LoginHelper.getUserId())) {
            return R.ok(MessageUtils.message("sys.third.unbind.QQ.success"));
        } else {
            return R.fail(MessageUtils.message("sys.third.unbind.QQ.fail"));
        }
    }

    /**
     * 绑定微信
     *
     * @Title:
     * @MethodName: bindQQ
     * [code]
     * @Return com.xinqi.common.base.response.R
     * @Exception
     * @Description:
     * @author: yyzhen
     * @date: 2023/3/8 15:40
     */
    @AsyncLog(title = "绑定微信", asyncType = AsyncType.USER_INFO, operatorType = AsyncOperaType.USER_THIRD_BIND)
    @GetMapping("/bindWeChat/{code}")
    public R<Void> bindWeChat(@PathVariable String code) {
        if (userThirdBindService.bindWeChat(LoginHelper.getUserId(), code)) {
            return R.ok(MessageUtils.message("sys.third.bind.WeChat.success"));
        } else {
            return R.fail(MessageUtils.message("sys.third.bind.WeChat.fail"));
        }

    }

    /**
     * 解绑微信
     *
     * @Title:
     * @MethodName: unbindWechat
     * []
     * @Return com.xinqi.common.base.response.R
     * @Exception
     * @Description:
     * @author: yyzhen
     * @date: 2023/3/8 11:44
     */
    @AsyncLog(title = "解绑微信", asyncType = AsyncType.USER_INFO, operatorType = AsyncOperaType.USER_THIRD_BIND)
    @PostMapping("unbindWeChat")
    public R<Void> unbindWeChat() {
        if (userThirdBindService.unbindWeChat(LoginHelper.getUserId())) {
            return R.ok(MessageUtils.message("sys.third.unbind.WeChat.success"));
        } else {
            return R.fail(MessageUtils.message("sys.third.unbind.WeChat.fail"));
        }
    }

}
